/******************************************************************
 * @version      : 1.0
 * @Author       : zhl
 * @Date         : 2023-06-26 15:24:33
 * @LastEditors  : zhl
 * @E-Mail       : zhll168@163.com
 * @Description  : 业务描述
 ******************************************************************/
#include "CONNECT-Response.h"
#include "DLT698-Frame.h"

ConnectResponse::ConnectResponse(/* args */)
{
}

ConnectResponse::~ConnectResponse()
{
}

int ConnectResponse::packet(uint8_t* data, int& len, CONNECT_RESPONSE_FRAME repFrame, int start){
    if((NULL== data) || (start > len) || (1 > len)){
        return -1;
    }
    int offset = 0;
    data[start] = DLT698Frame::getInstance().get_piid_acd();
    offset += 1;
    memcpy(data+start+offset, repFrame.factory.vendor_code, sizeof(repFrame.factory.vendor_code));
    offset += sizeof(repFrame.factory.vendor_code);
    memcpy(data+start+offset, repFrame.factory.software_ver, sizeof(repFrame.factory.software_ver));
    offset += sizeof(repFrame.factory.software_ver);
    memcpy(data+start+offset, repFrame.factory.software_release_date, sizeof(repFrame.factory.software_release_date));
    offset += sizeof(repFrame.factory.software_release_date);
    memcpy(data+start+offset, repFrame.factory.hardware_ver, sizeof(repFrame.factory.hardware_ver));
    offset += sizeof(repFrame.factory.hardware_ver);
    memcpy(data+start+offset, repFrame.factory.hardware_release_date, sizeof(repFrame.factory.hardware_release_date));
    offset += sizeof(repFrame.factory.hardware_release_date);
    memcpy(data+start+offset, repFrame.factory.vendor_extend_info, sizeof(repFrame.factory.vendor_extend_info));
    offset += sizeof(repFrame.factory.vendor_extend_info);

    data[start+offset] = repFrame.protocol_ver;
    offset += sizeof(repFrame.protocol_ver);
    memcpy(data+start+offset, repFrame.protocol_conformance.value, sizeof(repFrame.protocol_conformance.value));
    offset += sizeof(repFrame.protocol_conformance.value);
    memcpy(data+start+offset, repFrame.function_conformance.value, sizeof(repFrame.function_conformance.value));
    offset += sizeof(repFrame.function_conformance.value);
    data[start+offset] = repFrame.frame_max_size;
    offset += sizeof(repFrame.frame_max_size);
    data[start+offset] = repFrame.recv_max_size;
    offset += sizeof(repFrame.recv_max_size);
    data[start+offset] = repFrame.recv_max_window_size;
    offset += sizeof(repFrame.recv_max_window_size);
    data[start+offset] = repFrame.handle_fame_max_size;
    offset += sizeof(repFrame.handle_fame_max_size);
    data[start+offset] = repFrame.expected_timeout;
    offset += sizeof(repFrame.expected_timeout);
    data[start+offset] = repFrame.connect_response.result;
    offset += 1;
    //缺少内容,处理ConnectResult内容,长度没处理
    memcpy(data+start+offset, repFrame.connect_response.security_data.RN, sizeof(repFrame.connect_response.security_data.RN));
    offset += sizeof(repFrame.connect_response.security_data.RN);
    memcpy(data+start+offset, repFrame.connect_response.security_data.signature, sizeof(repFrame.connect_response.security_data.signature));
    offset += sizeof(repFrame.connect_response.security_data.signature);

    return offset;
}

int ConnectResponse::unpack(uint8_t* data, int& len, int start){

}